package com.xmx.ndmallwxapi.controller;


import com.xmx.common.holder.LoginUserHolder;
import com.xmx.common.utils.R;
import com.xmx.ndmallwxapi.feign.OrderFeignClient;
import com.xmx.ndmallwxapi.service.OrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/wx/order")
public class OrderController {

    @Resource
    OrderService orderService;

    @Resource
    LoginUserHolder userHolder;

    @Resource
    OrderFeignClient orderFeignClient;

    @PostMapping("/submit2")
    public R submitorder(@RequestBody Map<String ,Object> getdata){
//        Integer userId = 1;
        Integer userId = userHolder.getCurrentUser().getId();
        R submitorder = orderService.submitorder(userId, getdata);
        return submitorder;
    }

    @PostMapping("/submit")
    public R submitorder2(@RequestBody Map<String ,Object> getdata){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        RequestContextHolder.setRequestAttributes(requestAttributes);
        R submitorder = orderFeignClient.submitOrder(getdata);
        return submitorder;
    }
}
